<?php

/**
 * 静态属性和类绑定
 * 父类定义静态/常量属性名  子类未定义 子类就会调用父类的静态属性
 * 父类和子类 都定义了静态属性
 *   是两个静态属性
 */
class animal
{
    const VERSION = "1.0";
    public static $name = "animal";
    #private static $instance;
    protected static $instance;
    #public static $instance;
    

    public static function showName()
    {
        echo static::$name;
    }

    public static function getSelfInstance()
    {
        echo "get self\n";
        if (is_null(self::$instance)) {
            self::$instance = new static();
        }
        return self::$instance;
    }

    public static function getInstance()
    {
        //echo "get getInstance ", static::class , " \n";
        //var_dump(static::$instance);
        if (is_null(static::$instance)) {
        //    echo "new instance\n";
            static::$instance = new static();
        }
        return static::$instance;
    }

}

class dog extends animal
{
    const VERSION = "2.0";
    public static $name = "Dog";

 #   public static $instance;

}


var_dump(
    animal::$name, dog::$name
    //animal::VERSION, dog::VERSION,
    //get_class(animal::getInstance()), get_class(dog::getInstance())
);

$animal = animal::getInstance();
$dog = dog::getInstance();

var_dump($animal, $dog);
